#ifndef LINERENDERER_H
#define LINERENDERER_H

#include <QVector3D>
#include <QVector>

#include <qrender/renderer.h>

class QOpenGLShaderProgram;
class QOpenGLVertexArrayObject;
class QOpenGLBuffer;

class LineRenderer : public Renderer
{
    enum LineType
    {
        LineType_Start2End = 0, ///< 两点间线段
        LineType_Points, ///< 多点连续线段 {A, B, C, ...} -> {AB, BC, ...}
    };

public:
    LineRenderer();
    ~LineRenderer();

    void setPosition(const QVector3D &pos);
    void setShape(const QVector3D &start, const QVector3D &end,
                  const QVector4D &color);
    void setShape(const QVector<QVector3D> &points, const QVector4D &color);
    void setColor(const QVector4D &color);

protected:
    void create() override;
    void render(const CameraInfo &camera) override;
    void release() override;

private:
    QVector3D pos_{ 0.0, 0.0, 0.0 };

    LineType type_{ LineType_Start2End };

    QVector3D start_{ 0.0, 0.0, 0.0 };
    QVector3D end_{ 0.0, 0.0, 0.0 };

    QVector4D color_{ 1.0, 0.0, 0.0, 1.0 };

    bool data_changed_{ true };

    std::shared_ptr<QOpenGLShaderProgram> program_{ nullptr };
    std::shared_ptr<QOpenGLVertexArrayObject> vao_{ nullptr };
    std::shared_ptr<QOpenGLBuffer> vbo_{ nullptr };

    QVector<QVector3D> vertices_;
};

#endif // LINERENDERER_H
